/**
 * Title: BinaryHttpResponseHandler.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-8-12 下午2:33:11
 * Version 1.0 
 */
package com.luoxudong.phonenumber.service.net.http.asynchttp;

import java.util.Map;

import android.os.Message;

/** 
 * ClassName: BinaryHttpResponseHandler 
 * Description:文件传输回调返回
 * Create by 罗旭东
 * Date 2013-8-12 下午2:33:11 
 */
public class BinaryHttpResponseHandler extends AsyncHttpResponseHandler{
	/**
	 * 文件传输开始
	 */
	protected static final int START_TRANSFER_MESSAGE = Integer.MAX_VALUE - 1;
	
	/**
	 * 文件传输结束
	 */
	protected static final int FINISH_TRANSFER_MESSAGE = Integer.MAX_VALUE - 2;
	
	/**
	 * 暂停
	 */
	protected static final int PAUSE_TRANSFER_MESSAGE = Integer.MAX_VALUE - 3;
	
	/**
	 * 文件传输成功
	 */
	protected static final int SUCCESS_TRANSFER_MESSAGE = Integer.MAX_VALUE - 4;
	
	/**
	 * 下载文件信息
	 */
	protected int transferId = -1;
	
	/**
	 * 文件大小
	 */
	protected long fileSize = 0;
	
	
	public BinaryHttpResponseHandler(int transferId)
	{
		this.transferId = transferId;
	}
	
	protected void sendStartTransferMessage() {
        sendMessage(obtainMessage(START_TRANSFER_MESSAGE, null));
    }

    protected void sendFinishTransferMessage() {
        sendMessage(obtainMessage(FINISH_TRANSFER_MESSAGE, null));
    }
    
    @Override
    protected void handlerMessageCustom(Message msg) {
    	switch (msg.what) {
		case START_TRANSFER_MESSAGE:
			onTransferStart();
			break;
		case FINISH_TRANSFER_MESSAGE:
			onTransferFinish();
			break;
		case PAUSE_TRANSFER_MESSAGE:
			onTransferPause();
			break;
		case SUCCESS_TRANSFER_MESSAGE:
			onTransferSuccess();
			break;
		default:
			break;
		}
    }
	
	/**
	 * 添加头部信息
	 * @param headerFields
	 * @return void
	 */
	public void addHttpHeader(Map<String, String> headerFields) {
		
	}
	
    protected void onTransferStart() {}

    protected void onTransferFinish() {}
    
    protected void onTransferSuccess() {}
    
    protected void onTransferPause(){};
    
	public void setFileSize(long fileSize)
	{
		this.fileSize = fileSize;
	}
	
	public long getFileSize() {
		return fileSize;
	}
}
